

const fs = require('fs');
const path = require('path');

const cwd = process.cwd();
console.log(cwd);
const filePath = path.join(cwd.toString(), '../../settings/v2/packages/engine.json');
console.log(filePath);

// 异步读取JSON文件
fs.readFile(filePath, 'utf8', (err, data) => {
    if (err) throw err;

    // 解析JSON字符串为对象
    const obj = JSON.parse(data);
    console.log(obj);

    // 修改数据
    if (!obj.macroCustom) {
        obj.macroCustom = [];
    }

    obj.macroCustom.push({
        "key": "MLA_PHYSICS_MODULE",
        "value": false
    });

    obj.macroCustom.push({
        "key": "MLA_ANALYTICS_MODULE",
        "value": false
    });
    obj.macroCustom.push({
        "key": "MLA_SUPPORTED_TRAINING_PLATFORM",
        "value": false
    });


    // 将修改后的对象转换为字符串
    const jsonData = JSON.stringify(obj, null, 2);

    // 回写到文件
    fs.writeFile(filePath, jsonData, (err) => {
        if (err) throw err;
        console.log('添加宏定义成功！');
    });
});